$(document).ready(function () {
    // getEstateList("{\"recordUserName\":\"汪颖\",\"recordIdNumber\":\"421083199706070000\",\"deviceNumber\":\"1\"}")
});
var num; // 选中的业务
var str
$(document).on('click', '.imgOn', function () {
    $(this).attr("src", "static/img/checkBox_Off.png");
    $(this).attr("class", "imgOff");
    showMessage(this);
})
$(document).on('click', '.imgOff', function () {
    $(this).attr("src", "static/img/checkBox_On.png");
    $(this).attr("class", "imgOn");
    str = $(this).attr('id').toString()
    num = Number(str.substr(str.length - 1, 1));
    showMessage(this);
})
var bizs;     //查到总记录
var size;    //页数
var bizs2;   //所有记录数
var generalStoreReq // 客户端请求数据
var deviceNumber // 设备号

/* 客户端通过监听访问js方法并传值 */
function getEstateList(jsonStr) {
    // json转对象
    generalStoreReq = JSON.parse(jsonStr)
    // console.log(generalStoreReq.recordUserName+"--"+generalStoreReq.recordIdNumber+"--"+generalStoreReq.deviceNumber)
    var ob = {
        'recordUserName': generalStoreReq.recordUserName,
        'recordIdNumber': generalStoreReq.recordIdNumber
    }
    deviceNumber = generalStoreReq.deviceNumber
    // console.log(ob.recordUserName+"--"+ob.recordIdNumber)
    $.ajax({
        type: "post",
        url: "queryStoreBusiness",
        async: true,
        dataType: 'json',
        data: ob,
        success: function (data) {
            if (data.result) {
                $('.transit').hide();
                $('.listTable').show();
                $('#dataList').empty();
                $('.operation').show();
                bizs = JSON.parse(data.respJson);
                bizs2 = bizs;
                /*  size = Math.ceil(bizs2.length / 10);
                  if (size > 1) {
                      $('.page-down').show();
                  }*/
                for (var i = 0; (i < bizs.length) && (i < 10); i++) {
                    var biz = bizs[i];
                    var chkId = 'imgChk_' + i;
                    var bizNumber = biz.businessNumber;

                    $('#dataList')
                        .append(' <tr>' +
                            '<td class="icon_td"><img src="static/img/checkBox_Off.png" class="imgOff" id="'
                            + chkId +
                            '" /></td><td class="number_td">'
                            + bizNumber + '</td></tr>');
                }
                $('#imgChk_0').attr("src", "static/img/checkBox_On.png");
                $('#imgChk_0').attr("class", "imgOn");
                num = 0;
                $('.operation').show();
            } else {
                // 查无数据
                $('.transit font').empty();
                $('.transit font').append(data.respMsg);
                $('#home').show();
            }
        },
        error: function (data) {
            layer.alert("error:" + data)
        }
    });
}

function showList(list) {
    layer.alert("showList:" + list)
}

//单选操作
function showMessage(obj) {
    //1、将已经点击的图片恢复原状
    $(".imgOn").attr("src", "static/img/checkBox_Off.png");
    $(".imgOn").attr("class", "imgOff");
    //2、获取当前已经点击的元素属性
    var nowClass = $(obj).attr("class");
    //3、更换当前已经点击的元素属性
    $(obj).attr("src", "static/img/checkBox_On.png");
    //4、更改 当前的class 属性值
    $(obj).attr("class", "imgOn");
}

function exitIndex() {
    clientScript.home();
}

function store() {
    var biz = bizs[num]
    biz.deviceNumber = deviceNumber
    // console.log(biz.businessNumber + "--" + biz.businessType + "--deviceNumber" + biz.deviceNumber);
    var json = JSON.stringify(biz)
    $.ajax({
        type: "post",
        url: "storeInfo",
        async: true,
        dataType: 'json',
        data: biz,
        success: function (data) {
            layer.alert(data.result + data.respJson)
            if (data.result) {
                clientScript.userStore(data.respJson);
            } else {
                // 没有空格了
                $('.listTable').hide();
                $('#store').hide();
                $('.transit font').empty();
                $('.transit font').append(data.respMsg);
            }
        },
        error: function (data) {
            layer.alert("error:" + data)
        }
    });
}
